<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	template="/WEB-INF/template.xhtml">
	<ui:define name="title">Key Stores</ui:define>
	<ui:define name="body">
		<h:outputScript library="js" name="key-stores.js" target="head" />
		<h:form id="mainForm">
			<p:dataTable id="table" var="row" value="#{hsmProxyKeyStore.list}"
				paginator="true" rows="10">
				<p:column>
					<f:facet name="header">Name</f:facet>
					<h:outputText value="#{row.name}" />
				</p:column>
				<p:column>
					<f:facet name="header">State</f:facet>
					<h:outputText value="#{row.keyStoreState}" />
				</p:column>
				<p:column>
					<f:facet name="header">Actions</f:facet>

					<p:commandLink id="removeButton" styleClass="ui-icon ui-icon-trash"
						style="display:inline-block;"
						actionListener="#{hsmProxyKeyStore.selectKeyStore}"
						oncomplete="removeDialog.show();" update=":messages,:removeForm">
						<f:attribute name="selectedKeyStore" value="#{row}" />
					</p:commandLink>
					<p:tooltip for="removeButton" value="Remove key store..." />

					<p:commandLink id="viewButton" styleClass="ui-icon ui-icon-search"
						style="display:inline-block;"
						action="#{hsmProxyKeyStore.viewKeyStore(row)}" ajax="false" />
					<p:tooltip for="viewButton" value="View key store..." />

					<p:commandLink id="editButton" styleClass="ui-icon ui-icon-wrench"
						style="display:inline-block;"
						actionListener="#{hsmProxyKeyStore.selectKeyStore}"
						oncomplete="editDialog.show();" update=":messages,:editForm">
						<f:attribute name="selectedKeyStore" value="#{row}" />
					</p:commandLink>
					<p:tooltip for="editButton" value="Configure key store..." />
				</p:column>
				<f:facet name="footer">
					<h:panelGroup style="display:block; text-align: left;">
						<p:commandLink id="addButton" onclick="addDialog.show();"
							styleClass="ui-icon ui-icon-circle-plus"
							style="display:inline-block;" />
						<p:tooltip for="addButton" value="Add key store..." />
					</h:panelGroup>
				</f:facet>
			</p:dataTable>
		</h:form>

		<p:dialog widgetVar="addDialog" header="Add key store" modal="true">
			<h:form id="addForm">
				<h:panelGrid columns="3">
					<h:outputText value="Name:" />
					<h:inputText id="name" value="#{hsmProxyKeyStore.name}"
						required="true" />
					<p:message for="name" />

					<h:outputText value="Type:" />
					<p:selectOneMenu id="type" value="#{hsmProxyKeyStore.type}"
						valueChangeListener="#{hsmProxyKeyStoreType.changeType}">
						<f:selectItems value="#{hsmProxyKeyStore.types}" />
						<p:ajax event="change" update="slotListIndex" />
					</p:selectOneMenu>
					<p:message for="type" />

					<h:outputText value="Path:" />
					<h:inputText id="path" value="#{hsmProxyKeyStore.path}"
						required="true" size="30" />
					<p:message for="path" />

					<h:outputText value="Password:" />
					<h:inputSecret id="password" value="#{hsmProxyKeyStore.password}"
						required="true" />
					<p:message for="password" />

					<h:outputText value="Slot list index:" />
					<p:spinner id="slotListIndex"
						value="#{hsmProxyKeyStore.slotListIndex}"
						disabled="#{hsmProxyKeyStoreType.noSlotListIndex}" />
					<p:message for="slotListIndex" />
				</h:panelGrid>
				<p:commandButton value="Add"
					actionListener="#{hsmProxyKeyStore.add}"
					oncomplete="handleAddKeyStoreRequest(xhr, status, args)"
					update="addForm,:messages,:mainForm" />
			</h:form>
		</p:dialog>

		<p:confirmDialog header="Remove Key Store"
			message="Are you sure to remove the key store?" severity="alert"
			widgetVar="removeDialog">
			<h:form id="removeForm">
				<p:commandButton id="removeButton" value="Yes"
					actionListener="#{hsmProxyKeyStore.removeSelectedKeyStore}"
					oncomplete="removeDialog.hide();" update=":messages,:mainForm" />
				<p:commandButton value="No" onclick="removeDialog.hide();" />
			</h:form>
		</p:confirmDialog>

		<p:dialog widgetVar="editDialog" header="Configure key store"
			modal="true">
			<h:form id="editForm">
				<h:panelGrid columns="3"
					rendered="#{hsmProxyKeyStore.selectedKeyStore != null}">
					<h:outputText value="Name:" />
					<h:inputText id="name"
						value="#{hsmProxyKeyStore.selectedKeyStore.name}" required="true" />
					<p:message for="name" />

					<h:outputText value="Type:" />
					<p:selectOneMenu id="type"
						value="#{hsmProxyKeyStore.selectedKeyStore.keyStoreType}">
						<f:selectItems value="#{hsmProxyKeyStore.types}" />
					</p:selectOneMenu>
					<p:message for="type" />

					<h:outputText value="Path:" />
					<h:inputText id="path"
						value="#{hsmProxyKeyStore.selectedKeyStore.path}" required="true"
						size="30" />
					<p:message for="path" />

					<h:outputText value="Password:" />
					<h:inputSecret id="password"
						value="#{hsmProxyKeyStore.selectedKeyStore.password}"
						required="true" />
					<p:message for="password" />

					<h:outputText value="Slot list index:" />
					<p:spinner id="slotListIndex"
						value="#{hsmProxyKeyStore.selectedKeyStore.slotListIndex}" />
					<p:message for="slotListIndex" />
				</h:panelGrid>
				<p:commandButton value="Save and Reload"
					actionListener="#{hsmProxyKeyStore.save}"
					oncomplete="handleSaveKeyStoreRequest(xhr, status, args)"
					update="editForm,:messages,:mainForm" />
			</h:form>
		</p:dialog>

	</ui:define>
</ui:composition>